package com.zhangdi.demo.es.entity;

import com.iowl.search.dto.*;
import com.zhangdi.demo.es.utils.DateUtils;
import com.zhangdi.demo.es.utils.NumberUtils;
import org.springframework.data.elasticsearch.annotations.*;

import java.util.ArrayList;

/**
 * Created by zhangdi on 2021/01/26 23:12:57.
 */
@Document(indexName = "iowl_company", shards = 1, replicas = 1)
public class CompanyDoc extends Company {
    private String sname;

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public void addProject(CompanyProject bean) {
        if (bean.getProjectComeSource() == 2) {
            addSKY(bean);
        } else if (bean.getProjectComeSource() == 3) {
            addGL(bean);
        } else if (bean.getProjectComeSource() == 4) {
            addSL(bean);
        }
    }

    public void addZB(CompanyProjectWinbidding bean) {
        CompanyZBProject dto = new CompanyZBProject();
        dto.setSourceType(1);
        dto.setProjectName(bean.getProjectName());
        dto.setAreaId((short) bean.getAreaId());
        dto.setArea(bean.getArea());
        dto.setMoney(bean.getMoney());

        dto.setStart(DateUtils.formatExact(bean.getProjectTime()));

        if (getZbList() == null) {
            setZbList(new ArrayList<>());
        }
        getZbList().add(dto);
    }

    void addSKY(CompanyProject bean) {
        CompanySKProject dto = new CompanySKProject();
        dto.setSourceType(2);
        dto.setProjectName(bean.getName());
        dto.setAreaId(bean.getAreaInfo_id());
        dto.setArea(bean.getArea());
        dto.setMoney(bean.getMoney());

        dto.setAcreage(NumberUtils.parseFloatTry(bean.getAcreage()));
        dto.setCatalogName(bean.getCatalog());

        if (getSkyList() == null) {
            setSkyList(new ArrayList<>());
        }
        getSkyList().add(dto);
    }

    void addGL(CompanyProject bean) {
        CompanyGLProject dto = new CompanyGLProject();
        dto.setSourceType(3);
        dto.setProjectName(bean.getName());
        dto.setAreaId(bean.getAreaInfo_id());
        dto.setArea(bean.getArea());
        dto.setMoney(bean.getMoney());

        dto.setLevelName(bean.getProdectLevel());
        dto.setCatalogName(bean.getCatalog());

        if (getGlList() == null) {
            setGlList(new ArrayList<>());
        }
        getGlList().add(dto);
    }

    void addSL(CompanyProject bean) {
        CompanySLProject dto = new CompanySLProject();
        dto.setSourceType(4);
        dto.setProjectName(bean.getName());
        dto.setAreaId(bean.getAreaInfo_id());
        dto.setArea(bean.getArea());
        dto.setMoney(bean.getMoney());

        dto.setLevelName(bean.getProdectLevel() + "." + bean.getJibie());

        if (getSlList() == null) {
            setSlList(new ArrayList<>());
        }
        getSlList().add(dto);
    }
}
